Previous Book Contents Book Index Next

Inside Macintosh: AppleScript Language Guide / Part 2 - AppleScript Language Reference
Chapter 6 - Expressions / Variables


Using Variables

To use the value of a variable in a script, include the variable in a command or expression. For example, the first statement in the following example creates a variable, called myName, whose value is the string "Mitch". The second statement uses the variable myName in place of a string as the default answer parameter of the Display Dialog command.

set myName to "Mitch"display dialog "What is your name?" default answer myName
If you assign a new value to a variable, it replaces the old value. The following script shows what happens when you assign a new value. It uses the Display Dialog command to display the values. Try running this script:

set myName to "Mitch"display dialog ("The value of myName is now " & myName) ¬
   buttons "Sure Is" default button 1
set myName to "Warren"display dialog ("The value of myName is now " & myName) ¬
   buttons "You Betcha" default button 1
The first Display Dialog command displays the value stored by the first assignment statement (the string "Mitch"). The next Display Dialog
command displays the value after the second assignment statement (the
string "Warren").


Previous Book Contents Book Index Next

© Apple Computer, Inc.
13 JUL 1996